package net.pugsplace.gpremacy.rules;

import java.io.File;
import java.util.ResourceBundle;
import java.util.Vector;
import java.util.logging.Logger;


public class RuleProxy {
	private static Logger log = Logger.getLogger(RuleProxy.class.getName());

	private final ResourceBundle bundle;
	private final Vector<Corporation> corporations;
	private final Vector<CountryType> countries;

	private String description;

	private final Vector<File> files;

	private String identifier;

	private Worldmap map;

	private Market market;

	private final Vector<OrderOfBattle> orderOfBattles;

	private final Vector<Phase> phases;

	private final Vector<Resource> resources;

	private int turnLimit;

	private final Vector<UnitType> units;

	private final Vector<WinningCondition> winningConditions;

	public RuleProxy() {
		units = new Vector<UnitType>();
		countries = new Vector<CountryType>();
		resources = new Vector<Resource>();
		corporations = new Vector<Corporation>();
		winningConditions = new Vector<WinningCondition>();
		phases = new Vector<Phase>();
		orderOfBattles = new Vector<OrderOfBattle>();
		files = new Vector<File>();
		map = null;
		market = null;
		bundle = null;
		turnLimit = 0;
		identifier = "Default";
		description = "No Description";
	}

	public void addCorporation(Corporation c) {
		corporations.add(c);
	}

	public void addFile(String path) {
		File f = new File(path);
		if (f.exists() && f.canRead()) {
			files.add(f);
		} else {
			log.severe("Cannot read file " + path);
		}
	}

	public void addOrderOfBattle(OrderOfBattle oob) {
		orderOfBattles.add(oob);
	}

	public void addPhase(Phase p) {
		phases.add(p);
	}

	public void addResource(Resource r) {
		resources.add(r);
	}

	public void addUnit(UnitType u) {
		units.add(u);
	}

	public void addWinningCondition(WinningCondition wc) {
		winningConditions.add(wc);
	}

	public void Country(CountryType u) {
		countries.add(u);
	}

	public RuleSet getRuleSet() {
		RuleSet rs = new RuleSet();
		rs.units = units.toArray(new UnitType[0]);
		rs.countries = countries.toArray(new Country[0]);
		rs.corporations = corporations.toArray(new Corporation[0]);
		rs.description = description;
		rs.identifier = identifier;
		rs.images = files.toArray(new File[0]);
		rs.market = market;
		rs.orderOfBattles = orderOfBattles.toArray(new OrderOfBattle[0]);
		rs.phases = phases.toArray(new Phase[0]);
		rs.resourceBundle = bundle;
		rs.resources = resources.toArray(new Resource[0]);
		rs.turnLimit = turnLimit;
		rs.winningConditions = winningConditions.toArray(new WinningCondition[0]);
		rs.worldmap = map;

		return rs;
	}

	public boolean isValid() {
		return true;
	}

	public void setDescription(String desc) {
		description = desc;
	}

	public void setIdentifier(String id) {
		identifier = id;
	}

	public void setMarket(Market m) {
		market = m;
	}

	public void setResourceBundle() {
		// TODO wha?
	}

	public void setTurnLimit(int limit) {
		turnLimit = limit;
	}

	public void setWorldMap(Worldmap m) {
		map = m;
	}
}
